import { serverUrl } from '@/config';
import { getToken } from '@/utils';

export const uploadFile = (file: File): Promise<any> => {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: serverUrl + '/household/common/ossUpload',
			file,
			header: {
				'Authorization': getToken(),
			},
			success(res) {
				resolve(JSON.parse(res.data));
			},
			fail(err) {
				reject(err);
			},
		});
	})
}

// 文件路径上传
export const uploadFileByPath = (filePath: string): Promise<any> => {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: serverUrl + '/household/common/ossUpload',
			filePath,
			name: 'file',
			header: {
				'Authorization': getToken(),
			},
			success(res) {
				resolve(JSON.parse(res.data));
			},
			fail(err) {
				reject(err);
			},
		});
	})
}